package com.junmeng.jdemo.recycler.viewbinding2;


import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;

import com.example.common.base.BaseActivityDelegate;
import com.example.common.recycler.decoration.GridMatchItemDecoration;
import com.example.common.recycler.decoration.GridWrapItemDecoration;
import com.example.common.recycler.viewbinding.BaseSingleViewBindingRecyclerAdapter;
import com.example.common.recycler.viewbinding.BaseViewBindingRecyclerAdapter;
import com.example.common.recycler.viewbinding.ViewBindingViewHolder;
import com.example.common.utils.CalculateUtil;
import com.junmeng.jdemo.databinding.ActivityTestViewBinding2Binding;
import com.junmeng.jdemo.databinding.ItemGridWrapEmojiBinding;

import java.util.List;

public class TestViewBinding2Activity extends BaseActivityDelegate {

    ActivityTestViewBinding2Binding binding;
    BaseViewBindingRecyclerAdapter adapter2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityTestViewBinding2Binding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
//        binding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        binding.recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
        binding.recyclerView.setAdapter(adapter2 = new BaseViewBindingRecyclerAdapter());
        binding.recyclerView.addItemDecoration(new GridMatchItemDecoration(3, 20, 10));
        adapter2.register(new Bean1BindView());
        adapter2.register(new Bean2BindView());
        adapter2.register(new Bean3BindView());


        adapter2.addItem(new Bean3BindView.Item());
        adapter2.addItem(new Bean1BindView.Item());
        adapter2.addItem(new Bean2BindView.Item());
        adapter2.addItem(new Bean3BindView.Item());
        adapter2.addItem(new Bean1BindView.Item());
        adapter2.addItem(new Bean2BindView.Item());
        adapter2.addItem(new Bean2BindView.Item());
        adapter2.addItem(new Bean2BindView.Item());
        adapter2.addItem(new Bean2BindView.Item());
        adapter2.addItem(new Bean2BindView.Item());
        adapter2.addItem(new Bean3BindView.Item());
        adapter2.addItem(new Bean3BindView.Item());
        adapter2.addItem(new Bean3BindView.Item());
        adapter2.addItem(new Bean3BindView.Item());
        adapter2.addItem(new Bean1BindView.Item());
        adapter2.addItem(new Bean2BindView.Item());
        adapter2.addItem(new Bean2BindView.Item());
        adapter2.addItem(new Bean3BindView.Item());
        adapter2.addItem(new Bean3BindView.Item());
        adapter2.addItem(new Bean1BindView.Item());
        adapter2.addItem(new Bean1BindView.Item());
        adapter2.addItem(new Bean1BindView.Item());
        adapter2.addItem(new Bean1BindView.Item());
        adapter2.addItem(new Bean3BindView.Item());


        initRecyclerView2();
    }

    private void initRecyclerView2() {
        int spanCount = 7;
        binding.recyclerView2.setLayoutManager(new GridLayoutManager(this, spanCount));
        binding.recyclerView2.addItemDecoration(new GridWrapItemDecoration(spanCount, 50));
        MyAdapter myAdapter = new MyAdapter();
        binding.recyclerView2.setAdapter(myAdapter);
        for (int i = 0; i < 99; i++) {
            myAdapter.addItem("" + i);
        }
    }


    private class MyAdapter extends BaseSingleViewBindingRecyclerAdapter<String, ItemGridWrapEmojiBinding> {


        @Override
        public void onBindView(@NonNull ViewBindingViewHolder<ItemGridWrapEmojiBinding> holder, int position, String o, @NonNull List<Object> payloads) {

        }
    }

}